<?php

namespace App\Models;

use Illuminate\Database\Eloquent\Factories\HasFactory;
use Illuminate\Database\Eloquent\Model;

class SmsRecord extends Model
{
    use HasFactory;

    protected $table = 'sp_sms_record';
    protected $primaryKey = 'id';
    public $timestamps = false;

    //获取是否收费
    public static function getIsChargee($is_charge)
    {
        $sms_record_is_charge = array(1 => '不收费', 2 => '收费'); //是否收费  1 不收费  2收费
        return getValue($is_charge, $sms_record_is_charge);
    }

    //获取发送状态
    public static function getSendStatus($send_status)
    {
        $sms_record_send_status = array(1 => '成功', 2 => '失败'); //发送状态：1成功 2失败
        return getValue($send_status, $sms_record_send_status);
    }

    //短信发送记录
    protected function GetSmsRecordList($pageSize, $where)
    {
        $select = array('sr.id', 'sr.member_id', 'o.trade_no as order_id', 'sr.mobile', 'sr.template_id', 'sr.content', 'sr.charging_num', 'sr.send_user',
            'sr.is_charge', 'sr.send_status', 'sr.reason', 'sr.create_time', 'st.sms_title', 'oa.username', 'su.shopname');
        $data = $this
            ->from('sp_sms_record as sr')
            ->leftjoin('sp_sms_template as st', 'st.id', 'sr.template_id')
            ->leftjoin('sp_other_admin as oa', 'oa.id', 'sr.send_user')
            ->leftjoin('sp_shop_user_2 as su', 'su.member_id', 'sr.member_id')
            ->leftjoin('sp_order_2 as o', 'o.id', 'sr.order_id')
            ->select($select)
            ->where($where)
            ->orderBy('sr.id', 'desc')
            ->paginate($pageSize);
        $data = $data ? $data->toArray() : [];
        return $data;
    }


}
